﻿<script language ="javascript" type="text/javascript" >
 <!-- 
  function NumberLetter(obj)
  {  //只允许输入数字和字母
      //debugger;
      var KeyCode = event.keyCode;
      if ((KeyCode<48 && KeyCode != 46 && KeyCode != 8 && KeyCode != 37 && KeyCode != 38 && KeyCode != 39 && KeyCode != 40) || (KeyCode >57 && KeyCode <65) || (KeyCode >90 && KeyCode<96 ) || KeyCode >105)
      {
        event.returnValue=false;        
      }
  }
  
  function Number(obj)
  {  //只允许输入数字
      var KeyCode = event.keyCode;
      if ((KeyCode<48 && KeyCode != 46 && KeyCode != 8 && KeyCode != 37 && KeyCode != 38 && KeyCode != 39 && KeyCode != 40) || (KeyCode >57 && KeyCode<96 ) || KeyCode >105)
      {
        alert("请输入大于0的整数");
                  obj.value = "";
                  return;
      }
  }
  
  
  function JudgeIsNumTwo(obj)
	      {
	    
              var keycode = event.keyCode;
              
             if((keycode >8) && (keycode <48) ||(keycode >57) &&(keycode <96)|| (keycode >105) &&(keycode <110) || (keycode >110) &&(keycode <190) || (keycode >190))
              {
                  alert("请输入大于0的数");
                  obj.value = "";
                  return;
              }
             
	      }
  
  function Enter(obj)
  {  //不允许按回车
      var KeyCode = event.keyCode;
      if (KeyCode == 13 )
      {
        event.returnValue=false;
        //alert("请切换到英文状态下,输入整数!");
      }
  }
  

function checkinput(obj)
{
	var str=obj.value;
	if(str.length==8)
	{
		var a = str.match( /^\d+$/);
		if (a == null&&str.length!=0) 
		{
			alert('请输入数字！');
			//var e=window.document.getElementById(sid);
			//if(e != null) e.focus();
			obj.focus();
			return false;
		} 
		//处理value
		//年
		var Year=str.substring(0,4);    //年
		var Month=str.substring(4,6);    //月
		var Day=str.substring(6,8);     //日
		JudgeStr(Year,Month,Day);
		str=Year+"-"+Month+"-"+Day;					
		obj.value=str;					
	}
	else if(str.length > 8)
	{
	    var aInputStr = str.split('-');
	    var Year=aInputStr[0];    //年
		var Month=aInputStr[1];    //月
		var Day=aInputStr[2];     //日
		
	    if(Year.length != 4 || Month.length != 2 || Day.length != 2)
	    {
	      alert('请输入8位数字;如: 2008-08-08');
		  return false;
		} 
		else
		{
		    JudgeStr(Year,Month,Day)	        					
		    str=Year+"-"+Month+"-"+Day;					
		    obj.value=str;	
		}
	}
}
			
function JudgeStr(Year,Month,Day)
{
    if(parseInt(Month)>12)
    {
	    alert('输入的月份数应小于等于12');
	    return false;
    }
    else if(parseInt(Month) == 4 || parseInt(Month) == 6 || parseInt(Month) == 9 ||parseInt(Month) == 11)
    {
        if(parseInt(Day)>30)
        {
	        alert('输入的天数应小于等于30');
	        return false;
        }
    }
    else if(parseInt(Month) == 2 )
    {
        if(parseInt(Day)>28)
        {
	        alert('输入的天数应小于等于28');
	        return false;
        }
    }
    else if(parseInt(Day)>31)
    {
	        alert('输入的天数应小于等于31');
	        return false;
     }
}


function window.onload()   //方向键控制
 {
     SetFocusToFirstControl();
 }
var curCtlIndex = 0;
var arrCtl = new Array();
var oldEvent = new Array();
function SetFocusToFirstControl()
{
    var i = 0,j = -1;
    for(i=0;i<document.forms[0].elements.length;i++)
    {
        if(document.forms[0].elements[i].tagName.toUpperCase() == 'INPUT' || document.forms[0].elements[i].tagName.toUpperCase() == 'SELECT' || document.forms[0].elements[i].tagName.toUpperCase() == 'TEXTAREA')
        {
            if(document.forms[0].elements[i].type.toUpperCase() != 'SUBMIT' && document.forms[0].elements[i].type.toUpperCase() != 'RESET' && document.forms[0].elements[i].type.toUpperCase() != 'HIDDEN' && document.forms[0].elements[i].type.toUpperCase() != 'BUTTON')
            {
                if(document.forms[0].elements[i].disabled == 'disabled' || document.forms[0].elements[i].disabled == true) 
                    continue;
                if(document.forms[0].elements[i].readOnly) 
                    continue;
                if(document.forms[0].elements[i].style.display =="none") 
                    continue;
                if(document.forms[0].elements[i].style.width == "0px")
                    continue;
                try
                {
                    j++;
                    arrCtl[j] = document.forms[0].elements[i];
                    arrCtl[j].blur();
                }
                catch(el)
                { }
            }
            document.forms[0].elements[i].onblur = onblur_handler;
            document.forms[0].elements[i].onfocus = onfocus_handler;
        }
        //alert(document.forms[0].elements[i].type + document.forms[0].elements[i].tagName);
    }
    //alert(arrCtl.length);
    for(i=0;i<arrCtl.length;i++)
    {
        try
        {
            arrCtl[i].focus();
            break;
        }
        catch(el)
        {}
    }
}
/**//*

*/
function document.onkeydown()
{
    var i = 0;
    if(event.keyCode == 13  || event.keyCode == 39 )
    {
        for(i=curCtlIndex+1;i<arrCtl.length;i++)
        {
            if(curCtlIndex < arrCtl.length - 1)
            {
                try
                {
                    curCtlIndex++;
                    arrCtl[curCtlIndex].focus();
                    return false;
                    //break;
                }
                catch(el)
                {}
            }
            else
            {
                //break;
            }
        }   
//        if(objSubmit != undefined && objSubmit != '' )
//            document.getElementById(objSubmit).click();
        return false;
    }
    else if(event.keyCode == 37)    // || event.keyCode == 38
    {
        for(i=curCtlIndex-1;i>=0;i--)
        {
            try
            {
                curCtlIndex--;
                arrCtl[curCtlIndex].focus();
                break;
            }
            catch(el)
            {}
        }
        return false;
    }
}

function onblur_handler()
{
    this.style.backgroundColor="White";
}

function onfocus_handler()
{
    for(i=0;i<arrCtl.length;i++)
    {
        if(this.id == '')
        {
            if(this.name == arrCtl[i].name)
            {
                curCtlIndex = i;
                break;
            }
        }
        else
        {
            if(this.id == arrCtl[i].id)
            {
                curCtlIndex = i;
                break;
            }
        }
    }
    this.style.backgroundColor="#BADBFC";
    return true;
}
   
 -->
</script> 
